package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.SuppliersManageDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.SuppliersInfo;
import com.sls.game.pojo.SuppliersManageParameter;

@Repository("suppliersManageDAO")
public class SuppliersManageDAOImpl extends SuperDAO<SuppliersInfo> implements
		SuppliersManageDAO {

	/**
	 * 供应商新增
	 * 
	 * @param suppliersInfo
	 */
	@Override
	public void insert(SuppliersInfo suppliersInfo) {
		this.getSqlSession().insert("mybatis.xml.SuppliersManageMapper.insert",
				suppliersInfo);
	}

	/**
	 * 供应商修改
	 * 
	 * @param suppliersInfo
	 */
	@Override
	public void update(SuppliersInfo suppliersInfo) {
		this.getSqlSession().update("mybatis.xml.SuppliersManageMapper.update",
				suppliersInfo);
	}

	/**
	 * 查询供应商最大Id值
	 * 
	 * @param suppliersInfo
	 */
	@Override
	public String query() {
		String supplyId = null;
		supplyId = this.getSqlSession().selectOne(
				"mybatis.xml.SuppliersManageMapper.query");
		return supplyId;
	}

	/**
	 * 根据供应商ID查询某条记录
	 * 
	 * @param supplyId
	 */
	@Override
	public SuppliersInfo queryBySupplyId(String supplyId) {
		SuppliersInfo suppliersInfo = null;
		suppliersInfo = this.getSqlSession().selectOne(
				"mybatis.xml.SuppliersManageMapper.queryBySupplyId", supplyId);

		return suppliersInfo;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(SuppliersManageParameter pageInruire) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.SuppliersManageMapper.queryRowCount", pageInruire);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @return
	 */
	private List<SuppliersInfo> querySuppliersInfoList(
			SuppliersManageParameter pageInruire) {
		List<SuppliersInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.SuppliersManageMapper.querySuppliersInfoList",
				pageInruire);

		return list;
	}

	/**
	 * 供应商分页查询
	 * 
	 * @param pageInruire
	 * @param baseQuery
	 * @return
	 */
	@Override
	public Pagination<SuppliersInfo> queryPaginationList(
			SuppliersManageParameter pageInruire) {
		Pagination<SuppliersInfo> paginationList = null;
		Integer rowCount = queryRowCount(pageInruire);

		pageInruire.calculate();
		List<SuppliersInfo> list = querySuppliersInfoList(pageInruire);
		paginationList = this.queryPagination(rowCount, list, pageInruire);

		return paginationList;
	}

	@Override
	public String queryBySupplyName(String supplyName) {
		String id = this.getSqlSession().selectOne(
				"mybatis.xml.SuppliersManageMapper.queryBySupplyName",
				supplyName);
		return id;
	}

}
